(function(angular) {
	'use strict';
	angular.module('fs.waf').controller('cda.trustedSrc.viewController', viewController);
	viewController.$inject = [ '$scope', 'Constants', 'layoutConfig', 'validatorConfig', 'gridService', 'authService', 'trustedSrcService' ];
	function viewController($scope, Constants, layoutConfig, validatorConfig, gridService, authService, trustedSrcService) {
		var ctrl = this, params = $scope.$stateParams.params;
		ctrl.layoutConfig = layoutConfig;
		ctrl.trustedSrc = {};
		ctrl.init = function() {
			ctrl.innerGridOptions = gridService.createInnerGridOptions($scope, ctrl.layoutConfig.formConfigs.trustedSrcSites.tableConfigs.table, rowSelectionChanged);
			ctrl.innerGridOptions.data = 'vm.trustedSrc.trustedSrcSites';
			ctrl.innerGridOptions.verifyData = 'vm.trustedSrcOld.trustedSrcSites';
			ctrl.innerGridOptions.enableRowHeaderSelection = false;
			trustedSrcService.initDataOptions(ctrl);
			function rowSelectionChanged(eventRow, selectedRows) {
				ctrl.selectedRowsSite = selectedRows;
			}
			
			return authService.view(params).then(function(response) {
				ctrl.trustedSrc = response.data;
				ctrl.trustedSrc.trustedSrcSites = ctrl.trustedSrc.trustedSrcSites || [];
				if (ctrl.trustedSrc.trustedSrcSites!= null && ctrl.trustedSrc.trustedSrcSites.length > 0){
					angular.forEach(ctrl.trustedSrc.trustedSrcSites, function (value, key) {
						if (!value.dataStatus ){
							value.dataStatus = 'V';
						} else {
							value.dataStatus = ctrl.trustedSrc.dataStatus;
						}
					});
				}
			}, angular.noop);
		};
	}
})(angular);